/**
 * 
 */
package com.jie.eclipse.pan.gef.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;

import com.jie.eclipse.pan.dao.QMDao;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.editors.utils.PanImageHelper;
import com.jie.eclipse.pan.gef.dialog.BaseDialog;
import com.jie.eclipse.pan.utils.ObjectHelper;

/**
 * @author yanjie
 *
 */
public class OpenDialogAction extends Action{
	private String dialogClass = null;
	private Object[] args = null;
	private BaseDataEntity config = null;
	
	/**
	 * 
	 */
	public OpenDialogAction(String dialogClass,Object[] args,BaseDataEntity config) {
		this.config = config;
		this.dialogClass = dialogClass;
		this.args = args;
		this.setText(this.config.gpsv("text"));
		this.setToolTipText(this.config.gpsv("tiptext",this.config.gpsv("text")));
		this.setImageDescriptor(
				PanImageHelper.getInstance().getImageDescriptor(
						this.config.gpsv("icon","icons/ext/fam/user_green.gif")));
	}
	
	@Override
	public void run() {
		Object obj = ObjectHelper.newInstance(dialogClass, args);
		if(obj != null && obj instanceof BaseDialog){
			BaseDialog dialog = (BaseDialog)obj;
			//1.設置默认值
			if("setPanConfig".equalsIgnoreCase(config.gpsv("action"))){
				dialog.setDefaultData(QMDao.getInstance().getPanConfig());
			}
			
			//打开对话框
			if(dialog.open() == Dialog.OK){
				if("setPanConfig".equalsIgnoreCase(config.gpsv("action"))){
					
				}
			}
			
		}
	}
}